<?php
	require_once( "functions/inc_systemFunctions.php" );
	page_header( "Wayne Schlegel Inc. | QuickAccess", true, "myflight" );
	
	/*
		this page can be loaded blank; then you have to insert a quick access code to find a product
		also you can access this page by reviews.php?qac=<your quick-access-code>
			(possible to use this with a qr-code; only redirect to this page)
	*/
?>

<?php
	if( !empty($_GET['qac'] ) ){
		$_POST['quickAccessCode'] = strtoupper( $_GET['qac'] );
	}

	if( empty( $_POST['quickAccessCode'] ) ){
		$_POST['quickAccessCode'] = "";
	} else {
		$_POST['quickAccessCode'] = strtoupper( $_POST['quickAccessCode'] );
	}
	if( strlen( $_POST['quickAccessCode'] ) > 4 ){
		$_POST['quickAccessCode'] = substr( $_POST['quickAccessCode'], 0, 4 );
	}
/*
	if( strlen( $_POST['quickAccessCode'] ) < 4 ){
		$add = "";
		for( $i=0; $i<( 4-strlen( $_POST['quickAccessCode'] ) ); $i++ ){
			$add .= "&bull;";
		}
		$_POST['quickAccessCode'] = $_POST['quickAccessCode'] . $add;
	}
*/
?>

			<form method="post" action="" class="iForm">
				<label for="quickAccessCode">short-code</label>
				<input type="text" name="quickAccessCode" id="quickAccessCode" style="text-transform: uppercase;" maxlength="4" value="<?=$_POST['quickAccessCode']?>">
				<input type="submit" value="find product">
			</form>

<?php
	if( !empty( $_POST['quickAccessCode'] ) ){
		// find products for quick-access-code
		$sql = "SELECT id FROM product WHERE quickAccessCode = '" . $_POST['quickAccessCode'] . "'";
		$res = mysql_query( $sql );
		$row = mysql_fetch_array( $res );
		showProductDetails( $row['id'] );




		?>
		<table class="iTable">
			<tr class="moreInformation">
				<td><a href="product-reviews.php?pid=<?=$row['id']?>"><img src="images/icons/reviews.png" align="absmiddle" /> show reviews</a></td>
			</tr>
			<tr class="moreInformation lastItem">
		<?php
			if( productOnShoppingList( $_SESSION['user_id'], $row['id'] ) === true ) {
			?>
				<td><a href="shopping-list.php?pid=<?=$row['id']?>"><img src="images/icons/shoppingList.png" align="absmiddle" /> on your shopping-list</a></td>
			<?php
			} else {
			?>
				<td><a href="product-addToShoppingList.php?pid=<?=$row['id']?>"><img src="images/icons/shoppingListAdd.png" align="absmiddle" /> add to shopping-list</a></td>
			<?php
			}
		?>
			</tr>
		</table>
<?php
	}
?>

<?php
	page_footer();
?>